<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./作业3样式.css">
    <style>
        th,td{
            width: 200px;
            height: 100px;
            text-align: center;
        }
        tbody tr{
            
        }
        .box{
            background-color: white;
        }
        tbody tr:hover{
            background-image: linear-gradient(to left,green,skyblue);
        }
    </style>
</head>
<body>
    <div class="box">
        <table border="1">
            <thead>
                <tr>
                    <th>姓名</th>
                    <th>年龄</th>
                    <th>性别</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                
            </tbody>
        </table>
    </div>
</body>
</html>
<script>
    var data=[{
        'mz':'张三',
        'nl':'20',
        'xb':'男'
    },{
        'mz':'李四',
        'nl':'19',
        'xb':'男'

    },{
        'mz':'王五',
        'nl':'20',
        'xb':'男'

    },{
        'mz':'赵六',
        'nl':'20',
        'xb':'男'

    },{
        'mz':'田七',
        'nl':'20',
        'xb':'男'

    }
    ]


    var tbody=document.querySelector('tbody')
    for(i=0;i<data.length;i++){
        //创建
    var tr=document.createElement('tr')
    //赋值
    tr.innerHTML=`
                <td>${data[i].mz}</td>
                <td>${data[i].xb}</td>
                <td>${data[i].nl}</td>
                <td><button onclick="del(this)">删除</button></td>
    `;
    //添加
    tbody.appendChild(tr)
    }
    //删除
    function del(a){
        for(i=0;i<data.length;i++){
            tbody.removeChild(tr)
        }
    }
</script>